works better and now allows ladder length as a criterion