Bug fixes, new setting, code structure