Refactor and cleanup after code review