added some debug and refactored something