First draft JS implementation