This version works but the code is really crappy and full of debugging stuff