Adds some fixes and refactoring