updated code [halfway]