cleaned up code and implemented a terrible hack, but corroutines are nice