modified to accommodate slopes