refactor of sql and jquery block