Refactored layout and fixed js bugs