Fixes bug with nested while