Moved code to proper places