additional features; reorganized code