formatted the files, fixed some bugs, tested on linux.