refactored with guru’s corrections