bugfixes and reducing redundancy