How to remain inside a function?