removed some serious code duplication