added multiple format response support with tests and cleaned up some code