fixed buffer > file bug
refactored: split into seperate functions
refactored and more tests