Fixed all errors. It needs code cleanings and better structure.