Code fix and remove old code