Added support for custom parameters, some minor clean up and comments.