Cleaned up and Modularized