border condition calculations added