Fixed file header, reorganized code