Added a bit more explanation
Fixed minor bugs, added check for directory existence
Cleaned up and made it work correctly