remove code duplicates, change first letter of exported functions to upper case, fix correct type usage