Reorganized code, slightly changed syntax