Refactor things

Added tests. Added 'query' param. Correct interaction handling.