Changed some stuff.
Added a comment.
Add a better filename collision prevention mechanism.
Fixed an issue with formatting and rand inclusiuon.