Code cleanup, bug fixing.