Added file type validatioion and cleaned up some old code