Fixing bugs, added event system, changed unit code style