Cleaned up If block added braces for readability