Several improvements and debugging