Completed vanilla js version