Code cleanup + abstraction