handling boudary conditions