Cleaning up and modularizing