Moved some code here and there.