Re-organized Cody's code