Moved functions from .prototype.* as inner function

I had trouble with "this" reference from callbacks on .prototype.*
functions