updated and clean up old code with brief analysis