refactoring code so no sucking library is needed