simplified function, removed unecessary variables