almost finish, ready for optimizing