First commit: fully functional version