Error checking optimized, slight tweaking