Refactored slope analysis code