Fix several bugs. Works now.