split out variables; fix bugs