simplified and shrunk basic functions code