rewrote logisitic function in a cleaner way