D6: Final Working code