JS warnings removed

No errors now :)
we need to move the function to the self object, to avoid unnecessary nesting :)