Fixed bugs and tried to optimize the unit behaviour