Fixed up some stuff and added debug mode