added option to removeempty values; moved functions to  service