Code cleanup

Remove unused functions
Make functions const/static where possible