a bit more robust version. final update coming soon