Added bugfixes and refactor todos