added a check && cleaned some stuff up