Improve codition checking to prevent errors and exceptions.