Refactored into js modules