Initial implementation. Some things are missing but it is functional enough