clean up code and update with brief analysis