Refactored code, fixed minor bug in successor