algorithm probably needs a little tweaking