Javascript enhancements, code cleanup