First runnable version. Several improvements.