move decls around
fix bug and remove debug printing