Cleaner JS implementation