Fixed everthing; first working version

Did too many changes to list them all; but basically everything works now.