refactor and improve tests