further changes to work better with framework. and moved a bit more code in to the framework