Refactor and optimization (=== on JS)