Cleaned up some imports etc, added debug printing