fixed bug in new code