Bugfix + some re-arranging