Code cleanup and refactoring. 

Made the boolean treatment consistent so that it would work when calling from in-app as well