Code refactoring
Implementation of prev