New pull request because I found a small bug in old one