added little clever logic