This functions looks a bit unusual, maybe it will better to do it like in nodejs querytring module?