added logging function for debugging and some debug lines