Separated into files. Added checking of filename.