Fixing garbage collection problem, and adding exception to give better error message.