Refactored type checks into separate functions