less hacky way for handling the boundary condition