Cleaned up the initial working code