refactored variable names, fixed availability check