Update sourcemap implementation

Implementing sourcemaps according to the feedback from @sokra. I also merged in the latest changes from master.