Moved and modified more code