Refactor, optimize