JS Code cleanup and some bugfixing for bootstrap 2