Fixing selection sort and properly closing streams after reading and writing from files.