Testing coverage

I was writing unit tests to get a 40% of coverage and fixing some issues that I found writing the tests. Removed some casts and static unused functions.