Bugfixes,Code Refactor