Refactoring, commenting, reordered alot of code parts. Added broker init and kill methods for better state control.