Refactored JS into module pattern