Refactored to avoid warnings

mainly small refactors and eliminate a compilation warning when compiling with -Wall