firt implementation, with comments and scaladocs