Slightly modified some code