Make dir param optional
Clean up code
Add list functionality (idea from mushee)