Minor bug fixes

Simplified JS structure.