refactor availability check
fix tests