Got most functionality working I think. Still need tests and error handling.