Changed from throwing exception to if then else statement, as it's less
costly