Error checking added for strange bug