first refactor

pretty big refactoring - decoupled behaviour from agent's code and
encapsulatd different behaviours into classes.
Plus general tidy up and few small fixes.