Final Code after testing on localhost