cleaned-up and fixed bugs