fixed errors kindly spotted and resolved by johnsensible