Move completion code to separate file