Fix several bugs, CoreData integration