Cleaned up code
Switched to long CLI options, fixed a few bugs