Fixed issues for upstream merge.
Changed library structure.