Improved const-correctness and used C++-recommended cast operators