Updated with changes that ali pointed out