JS refactoring + JS fixes for profile page