Refactored parseParameters and introduced a few safety checks