Moved stuff to utils, cleaned up code. Need to nail this all together.