Added infinite loops + bugfixes + error handling