Working but hacky
Clean up and add tests