TODO added. Some improvements and small bug fixes.