removed debug prints and cleaned up dup code