Using getopt for better parameter handling
Revamped threading implementation and lots of fixes and optimizations