removed some repeated code