ADDED THE FINAL CODE.. includes comments for each operation