Working final code