changed method names and comments for clarity, retested algorithm