fixed certain issues, fully working code