Use function(s) Robby suggested to ensure that only right results get accepted, and code is much cleaner too.
Fixing formatting issue from copy/paste