Refactored code using some boolean convenience functions to improve code...

... readability.

I'll add a second patch containing only reformatting once this patch has been accepted, to clean up the formatting problems encountered on the previous patch.