fixed many bugs and moved all methods from repository to entity