Fix some jslint errors

Used dot notation instead ['']
Define the functions before call them (placed needed functions at top)
Used {} to define object