Refactor and optimize WIP