Pulled out some functionality into distinct modules