some checks addded (null pointer etc.)