Working author's algorithm, needs tweaking