Fixed bug in the new code