Cleanup code a lot -- moved stuff into modules