Refactoring + misc. minor changes