Adding documentation and fixing some error situations