added support for parameters and cleaned code