Works, kinda. Still need to clean up and debug.