Improved logic and changed corresponding return values
Logical hotfix