Added format conversion and file saving

Also cleaned up logic throughout