updated to add 'class << self' and other minor changes