clean up code, make it have a nicer interface