Merged two functions that were stupidly separated (#111)
Also cleaned up a bit