Updated controller with write functionality