Rearranged code, removed needless imports.