Fixed many small bugs, style issues