Fixing exception for invalid operation