fixed bug with or condition
removed duplicated code
updated