Move code to proper place, remove obsolete code.