fixed possible future buggs, optimizing code with terniary operators