Cleaned up some code

code clean up and removed a structural bug