added comments and paramter checks