Refactored out missused functions and code cleaning