Refactored javascript and CSS