Refactored add parameter method to make more robust.