Code refactoring.  Fixed some bugs with gold/castle generation.