Fixed many errors, code clean up