make static functions non-static and do some refactoring