fix SQL queries, fix magellan module call