Heavy refactoring & code clean up performed (fixes #2)