LPS-39262 & LPS-36588

http://issues.liferay.com/browse/LPS-39262
http://issues.liferay.com/browse/LPS-36588

Rebased