added some consts, some cleanup

Signed-off-by: Michal Jarzabek <stiopa@gmail.com>
Is it appropriate to declare a function const if it's returning a mutable pointer?