Lots of refactoring. Added handle subsystem and other code to be completed