cleanup and added file saving
cleanup and scalafication