added correct code, annotated it for clarity, whille try to implement in the morning...