added more condition checks