fixes #165 1 a
better have logic in php - fixes #165 1 b
fixes #165 2 a