Bugfix: The while conditions where wrong in some functions