used cast to int instead of ternary operator