Some refactoring and major bug fixes
Merged changes