modification to change colors and reimplement algorithm