Code refactoring + cleanup