Several improvements and new code formatting