cleaned up code based on feedback and added optional parameters and required parameters