Basic functionality fully rewritten