Updated with final code