Refactored Javascript to uphold module design pattern.