updated algorithm and added notes