Made more changes to the logic