Refactored js, added resize handling