Add some Debug Functions and Fix some Bugs