Refactored js and fixed initial focus