first working version. still some parameters are not considered in query