cleaned up algorithm and styles